DECLARE @ImageTypeID int SET @ImageTypeID = 4

SELECT t_Page.*
FROM  t_Page INNER JOIN
               t_Image ON t_Image.ID = t_Page.ImageID
WHERE (t_Image.ApplicantID = 50) AND (t_Image.ImageTypeID IN (4,5))
ORDER BY PageNumber

--UPDATE t_Page SET PageNumber = 2 WHERE ID = 138562
--INSERT INTO t_Page(ImageID,PageNumber) VALUES(5115,10)
--DELETE t_Page WHERE ImageID = 5115 AND PageNumber = 10
EXEC s_MovePages_Ex 50,4,'2',5,0

SELECT t_Page.*
FROM  t_Page INNER JOIN
               t_Image ON t_Image.ID = t_Page.ImageID
WHERE (t_Image.ApplicantID = 50) AND (t_Image.ImageTypeIDIN (4,5))
ORDER BY PageNumber

EXEC s_Pages_Get_Ex 50,4,'PDF',''
EXEC s_Pages_Get_Ex 50,5,'PDF',''